package cn.bupt.adt.controller;

import cn.bupt.adt.constant.Constants;
import cn.bupt.adt.entity.autogenerate.UserAgreement;
import cn.bupt.adt.service.IUserAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/userAgreementManagement")
public class UserAgreementController {

    @Autowired
    IUserAgreementService userAgreementService;

    @RequestMapping("/detail")
    public ModelAndView detail() {
        ModelAndView mv = new ModelAndView(Constants.USERAGREEMENT_DETAIL);
        UserAgreement u = userAgreementService.getUserAgreement();
        if (u == null) {
            u = new UserAgreement();
            u.setId(1);
        }
        mv.addObject("userAgreement", u);
        return mv;
    }

    @RequestMapping("/edit")
    public ModelAndView tackedAndODetail(UserAgreement u) {
        ModelAndView mv = new ModelAndView("forward:/userAgreementManagement/detail");
        String oper_message = null;
//		System.out.println(u.getContent());
//		System.out.println("id:"+u.getId());
        mv.addObject("oper_message", oper_message);
        if (u.getId() != null) {
            if (userAgreementService.updateUserAgreement(u))
                oper_message = "修改成功！";
            else
                oper_message = "修改失败！";
        }
        mv.addObject("oper_message", oper_message);
        return mv;
    }
}
